package com.probox.modules.controller.platfom;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.platfom.PlatformSendSms;
import com.probox.common.entity.service.platfom.IPlatformSendSmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 短信发送记录Controller
 *
 *
 * @date 2021-06-22
 */
@RestController
@RequestMapping("/platform/sms")
public class PlatformSendSmsController extends BaseController {
    @Autowired
    private IPlatformSendSmsService platformSendSmsService;

    /**
     * 查询短信发送记录列表
     */
    @PreAuthorize(hasPermi = "platform:sms:list")
    @GetMapping("/list")
    public TableDataInfo list(PlatformSendSms platformSendSms) {
        startPage();
        List<PlatformSendSms> list = platformSendSmsService.queryList(platformSendSms);
        return getDataTable(list);
    }

    /**
     * 导出短信发送记录列表
     */
    @PreAuthorize(hasPermi = "platform:sms:export")
    @Log(title = "短信发送记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlatformSendSms platformSendSms) throws IOException {
        List<PlatformSendSms> list = platformSendSmsService.queryList(platformSendSms);
        ExcelUtil<PlatformSendSms> util = new ExcelUtil<PlatformSendSms>(PlatformSendSms.class);
        util.exportExcel(response, list, "短信发送记录数据");
    }

    /**
     * 获取短信发送记录详细信息
     */
    @PreAuthorize(hasPermi = "platform:sms:query")
    @GetMapping(value = "/{sendId}")
    public AjaxResult getInfo(@PathVariable("sendId") Long sendId) {
        return AjaxResult.success(platformSendSmsService.selectPlatformSendSmsById(sendId));
    }

    /**
     * 新增短信发送记录
     */
    @PreAuthorize(hasPermi = "platform:sms:add")
    @Log(title = "短信发送记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlatformSendSms platformSendSms) {
        return toAjax(platformSendSmsService.insertPlatformSendSms(platformSendSms));
    }

    /**
     * 修改短信发送记录
     */
    @PreAuthorize(hasPermi = "platform:sms:edit")
    @Log(title = "短信发送记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlatformSendSms platformSendSms) {
        return toAjax(platformSendSmsService.updatePlatformSendSms(platformSendSms));
    }

    /**
     * 删除短信发送记录
     */
    @PreAuthorize(hasPermi = "platform:sms:remove")
    @Log(title = "短信发送记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sendIds}")
    public AjaxResult remove(@PathVariable Long[] sendIds) {
        return toAjax(platformSendSmsService.deletePlatformSendSmsByIds(sendIds));
    }
}
